home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11056 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: dawn.mmm.com!news
  2. From: kjhopps@mmm.com (Kevin J Hopps)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: GOTO and C++.
  5. Date: 12 Mar 1996 15:08:36 GMT
  6. Organization: 3M - St. Paul, MN  55144-1000 US
  7. Message-ID: <4i441k$8nu@dawn.mmm.com>
  8. References: <4i2bm7$bmu@masala.cc.uh.edu>
  9. Reply-To: kjhopps@mmm.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. sukumar (sukku@menudo.uh.edu) wrote:
  13. > Hi,
  14. >     Are there any inherent problems with GOTO and C++. In my application,
  15. > I using GOTO and  it crashes. If I remove the goto and replace it with a flag,
  16. > everyting works fine. This is how the code looks:
  17.  
  18. > f()
  19. > {
  20.  
  21. >     char** n = NULL;
  22.  
  23. >     n = new char*[20];
  24. >     for(i=0; i<20; i++)
  25. >     n[i] = new char[10];
  26.  
  27. >     ...trivial error checking
  28.  
  29. >     if(error)
  30. >     goto CLEANUP;
  31.  
  32.  
  33. >     ...
  34. >     I use come RWCStrings (String class)  here 
  35. >     ...
  36.  
  37. > CLEANUP:
  38. >     for(i=0; i<20; i++)
  39. >     delete [] n[i];
  40.  
  41. >     delete [] n;
  42. > }
  43.  
  44. > The program crashes on delete [] n. If I remove the goto and replace it with 
  45. > the code at the CLEANUP, I am fine. I was testing the case where error is True.
  46. > The debugger says there is a problem in the RWCString class.
  47.  
  48. > I could only conclude that goto is causing the initialization of some vars to 
  49. > screw up.
  50.  
  51. > I'd appreciate it if someone can throw some light on this.
  52.  
  53. If you skip over the instantiations of the RWCStrings, they will not be
  54. initialized and will contain garbage.  However, when they go out of scope,
  55. their destructors will be called.  Probably this is corrupting the heap,
  56. so that the deletes after CLEANUP don't work properly.
  57. --
  58. Kevin J. Hopps, 3M Company     kjhopps@mmm.com
  59. Opinions are my own.  I don't speak for 3M.
  60.     But 3M speaks for me -- I did not write the following line:
  61.  
  62. Opinions expressed herein are my own and may not represent those of 3M.
  63.